﻿using System.Configuration;
using System.Web;
using Medianamik.Core.Configuration;

namespace Medianamik.Core.Bootstrapping
{
    internal class AutoBootstrapper : Bootstrapper
    {
       private static readonly MedianamikConfigSection _config = (MedianamikConfigSection)ConfigurationManager.GetSection(ConfigurationSectionName.MEDIANAMIK);
       
       private static Bootstrapper GetConfigBootstrapper()
       {
           var env = _config.ApplicationEnvironment;
           if (env == ApplicationEnvironment.Auto)
           {
               throw new ConfigurationErrorsException("ApplicationEvironmenent.Auto is invalid in web.config");
           }
           return GetBootstrapper(env);
       }
        
       public override void Configure(HttpApplication pApplication)
       {
           GetConfigBootstrapper().Configure(pApplication);
       }

        public override void Cleanup(HttpApplication pApplication)
        {
            GetConfigBootstrapper().Cleanup(pApplication);
        }
    }
}
